<?php
/**
 * Created by PhpStorm.
 * User: zhenl
 * Date: 2022/10/14
 * Time: 16:14
 */

namespace app\api\controller;


use app\BaseController;
use app\Request;
use common\models\ProductModel;

class Product extends BaseController
{
    /**
     * 商品列表
     *
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function lists(Request $request)
    {
        $param = $request->param();
        $where = [];
        $where[] = ['status', '=', 1];
        if($param['keyword']) {
            $where[] = ['name', 'like', '%'.$param['keyword'] .'%'];
        }
        $list = ProductModel::where($where)->select();
//        $list = ProductModel::where('status', '=', 0)->select();
        foreach ($list as $k => $v) {
            // 隐藏时间戳
            $v->hidden(['create_time', 'update_time', 'delete_time']);
        }

        // ['code' => 0, 'msg' => '成功', 'data' => ]
//        return $this->success(0, "Chenggong ", $list);
        return json([
            'code' => 0,
            'msg' => '成功',
            'data' => $list
        ]);
    }
}